import {commonParams} from './config'
import axios from 'axios'

export function getLyric(singerId) {
  const url = '/api/getLyric'

  const data = Object.assign({}, commonParams, {
    pcachetime: new Date(),
    songmid: singerId,
    loginUin: 0,
    hostUin: 0,
    format: 'jsonp',
    platform: 'yqq',
    needNewCode: 0
  })

  return axios.get(url, {
    params: data
  }).then((res) => {
    return Promise.resolve(res.data)
  })
}

export function getMusicPlayUrl(songs = []) {
  const url = '/api/getMusicUrl'

  const songmidArr = Array.from(songs, (music) => {
    return music.mid
  })

  const comm = {
    g_tk: 5381,
    uin: 0,
    format: 'json',
    ct: 23,
    cv: 0
  }

  const req = {
    module: 'vkey.GetVkeyServer',
    method: 'CgiGetVkey',
    param: {
      guid: '7249040480',
      songmid: songmidArr,
      songtype: [],
      uin: '0',
      loginflag: 0,
      platform: '23'
    }
  }

  const data = Object.assign({}, { comm }, { req_0: req })

  return axios.post(url, data).then((res) => {
    return Promise.resolve(res.data)
  })
}
